package controllor

import (
	"fitness/internal/service"
	"fitness/pkg/middleware"
	"github.com/gin-gonic/gin"
)

type UserController struct {
	UserService *service.UserService
	Rbac        *middleware.Rbac
}

func NewUserController(userService *service.UserService, Rbac *middleware.Rbac) *UserController {
	return &UserController{
		UserService: userService,
		Rbac:        Rbac,
	}
}

func (userApi *UserController) InitApiRouter(engine *gin.Engine) {
	user := engine.Group("/users")
	{
		//获取自己的信息
		user.GET("/me", middleware.Jwt, userApi.UserService.Me)
		//分页获取user
		user.GET("/page", middleware.Jwt, userApi.UserService.Page)
		//根据ID查找
		user.GET("/form/:userId", middleware.Jwt, userApi.UserService.GetUserForm)

		//修改用户
		user.PUT("/:userId", middleware.Jwt,
			userApi.Rbac.RbacAuth("sys:user:edit"), userApi.UserService.UpdateUser)

		//修改用户头像
		user.POST("/avatar", middleware.Jwt,
			userApi.Rbac.RbacAuth("sys:user:edit"), userApi.UserService.Avatar)
	}
}
